AddCSLuaFile("cl_init.lua")
AddCSLuaFile("shared.lua")
include("shared.lua")

function ENT:Initialize()
	self.Entity:SetModel("models/wystan/attachments/doctorrds.mdl") 
	self.Entity:PhysicsInit(SOLID_VPHYSICS)
	self.Entity:SetMoveType(MOVETYPE_VPHYSICS)
	self.Entity:SetSolid(SOLID_VPHYSICS)
	self.Entity:SetCollisionGroup(COLLISION_GROUP_NPC)
	local phys = self.Entity:GetPhysicsObject()

	if phys and phys:IsValid() then
		phys:Wake()
	end
end

function ENT:SpawnFunction( ply, tr )
    if ( !tr.Hit ) then return end
	
    local ent = ents.Create("upgr_reflexsight")
    ent:SetPos( tr.HitPos + tr.HitNormal * 16 ) 
    ent:Spawn()
    ent:Activate()
 
    return ent
end

function ENT:OnTakeDamage(dmginfo)
	self.Entity:GetPhysicsObject():AddVelocity(dmginfo:GetDamageForce() * 0.1)
end

function ENT:Use(activator, caller)
	local wep = activator:GetActiveWeapon()

	if activator:IsPlayer() then
		if activator.AttachDelay == nil or CurTime() > activator.AttachDelay then
			if wep:GetClass():find("^cstm_") then
				if wep.NoDocter != true and wep.ScopeStatus != 9 and wep:GetDTInt(3) == 0 then
					wep:NWATT(9, self.Entity:GetClass(), nil, true)
					//wep.ACOGStatus = 2
					self.Entity:Remove()
				end
			end
		end
	end
end

function ENT:OnRemove()
return false
end 